package com.haotian.builder;

/**
 * 创造者模式（Builder模式）   netty 和 java mail  均使用了此模式
 * @author 张昊天
 *
 */
public class Test20170706 {                                

	public int a;
	public int b;
	public int c;
	public String d;

	private Test20170706(Builder b) {
		this.a = b.a;
		this.b = b.b;
		this.c = b.c;
		this.d = b.d;
	}
	
	
	static class Builder implements IBuilder<Test20170706> {

		private Builder() {
		}

		public int a;
		public int b;
		public int c;
		public String d;

		public Builder setA(int a) {
			this.a = a; 
			return this;
		}
		public Builder setB(int b) {
			this.b = b; 
			return this;
		}
		public Builder setC(int c) {
			this.c = c; 
			return this;
		}
		public Builder setD(String d) {
			this.d = d; 
			return this;
		}
		@Override
		public Test20170706 build() {
			return new Test20170706(this);
		}

	}


	public static void main(String[] args) {
		
		//创建一个空的对象 也可以选择性 初始化某些属性
		Test20170706 test = new Test20170706.Builder().setA(1).setB(2).setD("初始化了 A和B还有D").build();
		
		
		System.out.println(test.a);
		System.out.println(test.b);
		System.out.println(test.c);
		System.out.println(test.d);
		
	}

}
